app.controller('subjectOneC2Controller', function($scope,$http ,$controller,$sce,$rootScope) {
	$controller('baseController' , {$scope:$scope});
	$scope.status = -1;
	if(localStorage.status){
		$scope.status = localStorage.status;
	}else{
		location.href="../login.html";
	}
	
	//信任video
    $scope.trustUrl = function(url){
    	return $sce.trustAsResourceUrl(url);
    }
    
	//重置题库 c2
	$scope.resetSubjectOneC2= function(){
		if($scope.status != 0){
			layer.msg('抱歉！您没有权限，请使用总管理账号',{icon:2});
		}else{
			
			layer.confirm('您确定要重置题库？', {
			  btn: ['确定','取消'] //按钮
			}, function(){
				var index = layer.load(0, {shade: false}); 
				$http.get("../subjectLC2/resetC2.do").success(function (res) {
			    	console.log(res);
			    	//关闭
			    	layer.close(index);
			    	if(res.success){
				    	layer.msg(res.message,{icon:1});
			      		
			      	  }else{
			      		layer.msg(res.message,{icon:1}); 
			      	  }
			    	
			    });
				
			}, function(){
				layer.msg('已取消重置',{icon:2});
			});	
		}
	}
	
	//搜索 分页
    $scope.question= {};
	$scope.search=function(page, rows){
		$http.post('../subjectLC2/search.do?page='+page+'&rows='+rows,$scope.question).success(
			function(response){
				console.log(response,'单选题列表');
				$scope.questionlist=response.rows;	//显示当前页数据
				$scope.paginationConf.totalItems=response.total;	//更新总记录数	
			}		
		);
	}
	
	
	$scope.currentques = {};
	
	//选择
	$scope.currentquestion = function(index){
		console.log(index);
//		var ques = $scope.questionlist[index];
		$scope.currentques = $scope.questionlist[index];
//		$("#question").val(ques.question);
//		$("#url").val(ques.url);
//		$("#image").attr("src",ques.url);
//		$("#video").attr("src",ques.url);
//		$("#item1").val(ques.item1);
//		$("#item2").val(ques.item2);
//		$("#item3").val(ques.item3);
//		$("#item4").val(ques.item4);
//		$("#answer").val(ques.answer);
//		$("#id").val(ques.id);
//		editor.txt.html(ques.explains);
//		$("#topicTypes").val(ques.topicTypes);
		editor.txt.html($scope.currentques.explains);
		$("#image").attr("src",$scope.currentques.url);
		$("#video").attr("src",$scope.currentques.url);
	}
	
	  //上传视频
    $scope.save = function() { 
        var fd = new FormData();
        var file = document.querySelector('input[type=file]').files[0];
//        var file = $scope.myFile;
        console.log(file);
        fd.append('video', file); 
         $http({
              method:'POST',
              url:"../article/uploadVideo.do",
              data: fd,
              headers: {'Content-Type':undefined},
              transformRequest: angular.identity 
               })   
              .success( function (response){
			      // 上传成功的操作
            	  console.log(response,'图片/视频链接');
            	  $scope.currentques.url = response.videoResult;
            	  $("#image").attr("src",$scope.currentques.url);
          		  $("#video").attr("src",$scope.currentques.url);
              }); 

     }
    
    //修改文章 提交
    $scope.saveContent = function(){
    	$scope.currentques.explains = editor.txt.html();
    	var question = $scope.currentques;
        $http.post('../subjectLC2/savSubject.do',question).success( function (res){
		      // 上传成功的操作
      	  console.log(res,'修改成功');
      	  if(res.success){
      		layer.msg(res.message,function(){
      			self.location.reload();
      		},{icon:1});
      		
      	  }else{
      		layer.msg(res.message,{icon:2}); 
      	  }

        }); 
        
        console.log($scope.currentques,'修改文章内容');
    }
	
})